home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / plain / contrib / settosize.tex < prev    next >
Encoding:
Text File  |  1993-02-03  |  3.3 KB  |  104 lines

  1.  
  2. %%% I need to be able to specify the width for text. I would like to
  3. %%% use the largest size (subject to a user specified maximum and
  4. %%% minimum). If the constraints mean that I cannot fill the width
  5. %%% then the text should be centered at the largest specified size.
  6. %%%
  7. %%% Phil Taylor January 1993
  8.  
  9. \catcode `\@ = 11
  10.  
  11. \newcount \r@mainder
  12. \newcount \m@gstepcount
  13. \newcount \m@gsteplimit
  14. \newcount \m@gstepvalue
  15. \newdimen \m@gstepdimen
  16.  
  17. \def \magsteps {\afterassignment \m@gsteps \m@gsteplimit = }
  18.  
  19. \def \m@gsteps
  20.     {\let \@r = \or
  21.      \def \or {\noexpand \or}%
  22.      \m@gstepdimen = 0.166667 \maxdimen
  23.      \m@gstepvalue = 1000 
  24.      \m@gstepcount = 0
  25.      \def \magstep {}%
  26.      \loop
  27.      \ifnum     \m@gstepcount < \m@gsteplimit
  28.                 \advance \m@gstepcount by 1
  29.                 \ifnum \m@gstepvalue > \m@gstepdimen
  30.                         \advance \m@gstepcount by -1
  31.                         \message {Sorry --- integer overflow would occur if
  32.                                         I went any further; stopped at 
  33.                                                 \the \m@gstepcount.}
  34.                         \m@gsteplimit = \m@gstepcount 
  35.                 \else
  36.                         \multiply \m@gstepvalue by 12
  37.                         \multiply \r@mainder by 12
  38.                         \divide \r@mainder by 10
  39.                         \advance \m@gstepvalue by \r@mainder
  40.                         \r@mainder = \m@gstepvalue
  41.                         \divide \m@gstepvalue by 10
  42.                         \multiply \m@gstepvalue by 10
  43.                         \advance \r@mainder by -\m@gstepvalue
  44.                         \divide \m@gstepvalue by 10
  45.                         \ifnum \r@mainder < 5
  46.                                \edef \magstep {\magstep \or \the \m@gstepvalue}%
  47.                         \else
  48.                                \advance \m@gstepvalue by 1
  49.                                \edef \magstep {\magstep \or \the \m@gstepvalue}%
  50.                                \advance \m@gstepvalue by -1
  51.                         \fi
  52.                 \fi
  53.      \repeat
  54.      \edef \magstep ##1%
  55.           {\noexpand \ifcase ##1
  56.                         1000\magstep 
  57.            \noexpand \else 0%
  58.            \noexpand \message 
  59.                 {Sorry --- \string \magstep \space ##1
  60.                                 is not in range 0 .. \the \m@gsteplimit}%
  61.            \noexpand \fi
  62.            \noexpand \relax
  63.           }%
  64.      \let \or = \@r
  65.     }
  66.  
  67. \catcode `\@ = 12
  68.  
  69. \magsteps 63
  70. \newcount \loopcount
  71. \newdimen \thewidth
  72.  
  73. \def \set #1 \in #2 \to %%% see example at end 
  74.     {\def \thetext {#1}%
  75.      \def \thefont {#2 }%
  76.      \afterassignment \settowidth
  77.      \thewidth =      
  78.     }
  79.  
  80. \def \settowidth
  81.     {\loopcount = 0
  82.      \loop
  83.        \message {Trying \noexpand \magstep \the \loopcount...}%
  84.        \setbox 0 = \hbox 
  85.            {\font \tempfont = \thefont scaled \magstep \loopcount
  86.                    \tempfont \thetext
  87.                   }%
  88.      \ifdim \wd 0 < \thewidth
  89.        \advance \loopcount by 1
  90.      \repeat
  91.      \advance \loopcount by -1
  92.      \message {The calculated font is \thefont \space 
  93.                scaled \noexpand \magstep \the \loopcount}%
  94.  
  95.      \hbox to \thewidth {\font \tempfont = \thefont scaled \magstep \loopcount
  96.                 \hss \tempfont \thetext \hss}%
  97.     }
  98.  
  99. \set Now is the time for \in cmr10 \to 50 cm
  100.  
  101.  
  102.  
  103.  
  104.